package com.qfedu.labsystem.controller;

import com.qfedu.labsystem.entity.bo.RoleBO;
import com.qfedu.labsystem.entity.vo.ResultOBJ;
import com.qfedu.labsystem.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName RoleController
 * @Author ykx
 * @Date 2024/4/5 18:32
 * @Version 1.0
 */
@RestController
@RequestMapping("adminapi/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    public List<RoleBO> getRoleList() {
        return roleService.getRoleList();
    }

    @PutMapping("/{id}")
    public ResultOBJ updateRoleList(@PathVariable Integer id, @RequestBody RoleBO roleBO) {
        try {
            roleBO.setId(id);
            roleService.updateRoleList(roleBO);
            return ResultOBJ.UPDATE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.UPDATE_ERROR;
        }
    }

    @DeleteMapping("/{id}")
    public ResultOBJ deleteRole(@PathVariable Integer id) {
        return ResultOBJ.success(roleService.deleteRole(id));
    }

}
